// web/src/app/(employee)/company-side/new-employee/actions/create-employee.ts
'use server'
import {db} from "@/lib/db";
import {Tag} from "@prisma/client";

export async function updateEmployee(values: {
    name: string
    description: string
    companyId: string
    salary: number
    // tags: { name: string }[]
    tags: string
    educationId: string
    cityId: string
    hrId: string
    id: string // employeeId
}) {
    let {tags, ...value} = values;
    let tags_split = tags.split(',')
    let tags_split_name = tags_split.map(t => ({
        name: t
    }))

    await db.tag.deleteMany({
        where: {
            employeeId: value.id
        }
    })
    return db.employee.update({
        data: {
            ...value,
            tags: {
                create: [
                    ...tags_split_name
                ],
            }
        },
        where: {id: value.id}
    });
}